package dao;

import java.util.List;

import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import bean.Entity;

public interface EntityDAO {
    @Insert("INSERT INTO test(var2) VALUES(#{val})")
    void addEntity(String val);
    
    @Update("UPDATE test SET var2=#{field2} WHERE var1=#{field1}")
    void modifyEntity(Entity value);
    
    @Delete("DELETE FROM test WHERE var1=#{val}")
    void removeEntity(int value);
    
    @Results(id = "map", value = {
            @Result(column = "var1", property = "field1"),
            @Result(column = "var2", property = "field2")
    })
    @Select("SELECT * FROM test WHERE var2 LIKE CONCAT(CONCAT('%',#{value}),'%') ORDER BY var1")
    List<Entity> selectEntities(String name);
    
    @ResultMap(value = "map")
    @Select("SELECT * FROM test WHERE var1=#{value}")
    Entity selectEntity(int field);
}